import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';

export default class UserForgetPwdAction extends BaseAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.USER;
    this.name = "UserForgetPwdAction";
  }

  call(caller, data) {
    this._baseCall(caller, data);
    this.caller.setState({
      viewStatus: 4,
    })
  }

  finish(data, isSucceed, response) {
    //let cloneResponse = data;
    //let json = cloneResponse.json();
    let detail = "";
    let updateSucess = false;
    if(isSucceed) {
      detail = "修改成功";
      updateSucess = true;
    }
    else if (response.status == ResponseConstants.status_unauthorized ||
        response.status == ResponseConstants.status_bad_request) {
      detail = response.detail ? response.detail : "验证码过期或者不正确";
    }
    else if (response.status == ResponseConstants.status_server_error) {
      detail = "服务器出错";
    }
    else {
      detail = "未知错误";
    }
    this.caller.setState({
      viewStatus: response.status,
      statusText: detail,
      updateSucess:updateSucess,
    })
  }
}
